<?php
namespace Admin\Controller;
//use Think\Controller;
class NewsController extends CommontController {
    //新闻添加
    public function add(){
        //实现新闻添加完成
        $newsModel=D("News");
        if(IS_POST){
            if($newsModel->create()){
                if($newsModel->add()){
                    $this->success("添加成功",U("News/index"));die;
                }else{
                    $this->error("添加失败".$newsModel->getError());
                }
            }else{
                $this->error($newsModel->getError());
            }
        }

        //渲染模板
        $this->display();
    }
    //新闻列表
    public function index(){
        $newsModel=D("News");
        $list=$newsModel->select();
        $this->assign('list',$list);
        $this->display();
    }
    //新闻修改
    public function upd(){
        $newsModel=D("News");
        //前台菜单修改完成
        if(IS_POST){
            if($newsModel->create()){
                if($newsModel->save()!==false){
                    $this->success("修改成功",U("News/index"));die;
                }else{
                    $this->error("修改失败");
                }
            }else{
                $this->error($newsModel->getError());
            }
        }
        //前台菜单回显
        $news_id=I('get.news_id');
        $list=$newsModel->find($news_id);
        $this->assign('list',$list);
        $this->display();  
    }
    //新闻删除
    public function del(){
        $newsModel=D("News");
        $news_id=I('get.news_id');
        $data=$newsModel->delete($news_id);
        if($data){
            $this->success("删除成功",U('News/index'));die;
        }else{
            $this->error("删除失败");
        }
    }
    
}